{{extend "tasks_layout.html"}}

{{block content_main}}
{{use "jquery", ui=True}}
{{use "jqutils"}}
{{use "jqeasyui"}}
{{include "inc_message.html"}}
<div class="content">
    {{if task_type == 'develop':}}
        {{if not has_plan:}}
            {{message('你还没有创建计划，将无法设置投产时间和及时报工，请及时创建.', 'attention')}}
        {{elif need_plans:}}
            {{message('存在以下未定义或未生效的计划：%s，请检查是否存在当前计划或主计划定义不完整的情况。' % ','.join(need_plans), 'attention')}}
        {{pass}}
    {{pass}}
    <div class="box box-panel">
        <h2>任务：{{=object.name}}</h2>
        <div class="box-body">
            {{<<view}}
            <div class="box-bottom">
                {{if task_type == 'develop':}}
                    {{if request.user.is_superuser:}}
                        <a class="btn btn-green" href="{{=get_url('transfer', obj_id)}}">任务迁移</a>
                    {{pass}}
                    {{if can_modify(object, task_type):}}
                        <a class="btn btn-green" href="{{=get_url('edit', obj_id)}}">编辑</a>
                    {{pass}}
                {{else:}}
                    {{if can_modify(object, task_type):}}
                        <a class="btn btn-green" href="{{=get_url('edit', obj_id)}}">编辑</a>
                        <a class="btn btn-blue" href="{{=get_url('update', obj_id)}}">更新月末工作量</a>
                    {{pass}}
                {{pass}}
                {{if can_delete(object, task_type):}}
                    <a class="btn btn-blue" href="{{=get_url('delete', obj_id)}}" onclick="return confirm('确定要删除当前记录吗？');">删除</a>
                {{pass}}
                {{if task_type == 'develop':}}
                    <a class="btn btn-green" href="{{=get_url('list')}}?only_mine=off&header_id={{=object.version_headerId or obj_id}}">查看相关任务</a>
                    <a class="btn btn-green" href="/weekreport/view?requirement={{=object._requirement_}}">周报查看</a>
                    {{if has_role(request.user,'selfdev_manager') and object.selfdev_if:}}
                    <a class="btn btn-green" id="selfdev_modified" href="#">不参与系统自主率考核</a>
                    {{pass}}
                    {{if has_role(request.user,'selfdev_manager') and not object.selfdev_if:}}
                    <a class="btn btn-green" id="selfdev_modified" href="#">参与系统自主率考核</a>
                    {{pass}}
                {{pass}}
                <script type="text/javascript">
                $(function(){
                        $('#selfdev_modified').click(function(event){
                            event.preventDefault();
                            $.ajax({
                                type: "POST",
                                data: {resource:'tasks_develop', object_id:{{=object.id}}},
                                url: "/selfdevs/selfdev_if/modified",
                                success: function(data){
                                    show_message(data.msg);
                                    if(data.selfdev_modified){
                                        $('#selfdev_modified').html(data.selfdev_modified);
                                        }
                                    if(data.selfdev_if){
                                        $('#selfdev_if').html(data.selfdev_if);
                                    }
                                }
                            });
                        });
                        
                    });
                </script>
            </div>
        </div>
    </div>

    {{if task_type == 'develop':}}
        {{include "inc_plan_list.html"}}
        <a href="#" name="questions"></a>
        <div class="box box-panel">
            <h2>问题跟踪</h2>
            <div id="questions" class="box-body">
                <div class="box-bottom">
                {{#if can_modify(object, task_type):}}
                <a class="btn btn-green" href="/ticket/questions/add?task={{=object.id}}">新问题</a>
                {{#pass}}
                </div>
            </div>
        </div>
        <script type="text/javascript">
        $(function(){
            $.ajax({
                type: "POST",
                url: "/ticket/questions/list?task={{=object.id}}&type=json",
                success: function(data){
                $('#questions').prepend(data.table);
                $('#question_table').datagrid({height:Math.min(22+23*(data.total+1), 300)});
                }
            });
        });
        </script>
        <a href="#" name="risks"></a>
        <div class="box box-panel">
            <h2>风险跟踪</h2>
            <div id="risks" class="box-body">
                <div class="box-bottom">
                {{#if can_modify(object, task_type):}}
                <a class="btn btn-green" href="/ticket/risks/add?task={{=object.id}}">新风险</a>
                {{#pass}}
                </div>
            </div>
        </div>
        <script type="text/javascript">
        $(function(){
            $.ajax({
                type: "POST",
                url: "/ticket/risks/list?task={{=object.id}}&type=json",
                success: function(data){
                $('#risks').prepend(data.table);
                $('#risk_table').datagrid({height:Math.min(22+23*(data.total+1), 300)});
                }
            });
        });
        </script>
    {{pass}}
    <a href="#" name="details"></a>
    <div class="box box-panel">
    <h2>阶段明细(工作量单位：人天)</h2>
    <div id="details" class="box-body"></div>
    <script type="text/javascript">
    $(function(){
        <!--$('#details').load("/tasks/details/{{=task_type}}/{{=obj_id}}");-->
        $.ajax({
            type: "POST",
            url: "/tasks/details/{{=task_type}}/{{=obj_id}}",
            success: function(data){
                $('#details').html(data);
            }
        });
    });
    </script>
    </div>
    {{include "inc_task_functions.html"}}
</div>
{{end}}
